package com.zhixiang.xaec.action.performance.safeachievements;

import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.util.String2Array;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.performance.safeachievements.RatingProjectSet;
import com.zhixiang.xaec.service.performance.safeachievements.RatingProjectSetService;

@Controller
@Scope("prototype")
public class RatingProjectSetAction extends BaseAction {

    private static final long serialVersionUID = 2450846878341637412L;

    private RatingProjectSet ratingProjectSet;

    @Autowired
    private RatingProjectSetService ratingProjectSetService;

    public String save() {
        ratingProjectSetService.save(ratingProjectSet);
        return SUCCESS;
    }

    public String get() {
        if (ratingProjectSet != null && StringUtils.isNotEmpty(ratingProjectSet.getRatingProjectSetTreeId().toString())) {
            setResult(ratingProjectSetService.get(ratingProjectSet.getRatingProjectSetTreeId()));
        }
        return SUCCESS;
    }
    public String getdetail() {
        Long id = Long.valueOf(getRequest().getParameter("id"));
        if (StringUtils.isNotEmpty(id.toString())) {
            setResult(ratingProjectSetService.get(id));
        }
        return SUCCESS;
    }

    public String list() {
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<RatingProjectSet> list = ratingProjectSetService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(list);
        return SUCCESS;
    }

    public String delete() {
        try {
            String ids = getRequest().getParameter("ids");
            Long[] l = String2Array.stringToLongArray(ids);
            ratingProjectSetService.remove(l);
        } catch (Exception e) {
            setSuccess(false);
            setMsg("删除失败");
        }

        return SUCCESS;
    }

    public RatingProjectSet getRatingProjectSet() {
        return ratingProjectSet;
    }

    public void setRatingProjectSet(RatingProjectSet ratingProjectSet) {
        this.ratingProjectSet = ratingProjectSet;
    }

}
